<?php
/**
 * Copyright (c) 2006-2007, Julien PORTALIER
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright    Copyright (c) 2006-2007, Julien PORTALIER
 * @link         http://featherphp.googlecode.com/
 * @license      http://www.opensource.org/licenses/mit-license.php The MIT License
 */

require APP.'config'.DS.'database.php';
require FEATHER.'database'.DS.'drivers'.DS.'db_base.php';

/**
 * Loads database backend (depending on configuration).
 */
class Database
{
	private static $configs = null;
	private static $dbo     = array();
	
	/**
	 * Returns asked DB link.
	 */
	static function get($ds='default')
	{
		if (!isset(self::$dbo[$ds]))
		{
			// config
			$conf = DatabaseConfig::$$ds;
			
			// driver
			$dbClass = 'db_'.$conf['driver'];
			require_once FEATHER.'database'.DS.'drivers'.DS."$dbClass.php";
			
			// created OBJ to DB
			self::$dbo[$ds] = new $dbClass(&$conf);
		}
		return self::$dbo[$ds];
	}
}
?>